package com.example.shiro_demo1.shiro;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;

/**
 * @author cxp
 * @version 1.0
 * @date 2019/6/27 10:55
 */
public class CredentialMatcher extends SimpleCredentialsMatcher {

    /**
     * 该方法可以自定义UsernamePasswordToken中的密码比较的方法，比如添加一个加密解密的过程
     * @param token
     * @param info
     * @return
     */
    @Override
    public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
        System.out.println("这边是密码校对");
        UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
        String password = new String(usernamePasswordToken.getPassword());
        //数据库里的密码
        String dbPassword = (String) info.getCredentials();
        return this.equals(password, dbPassword);
    }
}
